<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="../include/tag.jsp"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>选择文章</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp"%>
    <style type="text/css">
        .index-outside >section .section-main{
            min-width: 0px !important;
            max-width: 1200px!important;
        }
    </style>
</head><body>
<!--头部-->
<div class="index-outside">
    <!--内容-->
    <section  class="no-fix">
        <div class="section-main" style="padding: 15px;">
            <form class="layui-form" action="${ctx}/subject/apply/batchAdd/form.do" id="myForm" method="post">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <input type="hidden" name="channelId" id="channelId" value="${channelId}"/>
                <input type="hidden" name="applyId" id="applyId" value="${applyId}"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline">
                                <label class="search-form-lable">文章标题</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title"
                                           autocomplete="off" class="layui-input" value="${title}"
                                           placeholder="请输入昵称" style="width: 100px;">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger" id="submitBtn">确定</a>
                                    <a class="layui-btn layui-btn-normal" id="resetBtn">重置</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="c-time-list-content" style="padding-top: 0px;">
                <ul>
                    <table class="layui-table layui-form">
                        <colgroup>
                            <col width="50px">
                            <col width="200px">
                            <col width="120px">
                            <col width="100px">
                            <col width="70px">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" id="chkAll" lay-skin="primary" lay-filter="chkAll"/>
                            </th>
                            <th>文章标题</th>
                            <th>副标题</th>
                            <th>所属频道</th>
                            <th>阅读量</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="article" items="${articles}">
                            <tr>
                                <td>
                                    <input type="checkbox" name="id" value="${article.id}"
                                           lay-filter="member" title="&nbsp;" lay-skin="primary" class="member-chk">
                                </td>
                                <td class="ellipsis-1" title="${article.title}">
                                        ${article.title}
                                </td>
                                <td class="ellipsis-1" title="${article.subTitle}">
                                        ${article.subTitle}
                                </td>
                                <td>${article.channel.name}</td>
                                <td>${article.readNum}</td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </ul>
            </div>
            <div id="page_content" class="page-container"></div>
        </div>
    </section>
</div>
<!--底部-->
<%@include file="../include/incScript.jsp" %>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">
    $(function() {
        // 加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });

        layui.use([ 'form', 'laypage' ], function() {
            var form = layui.form;

            form.on('checkbox(chkAll)', function (data) {
                var checked = data.elem.checked;
                if (checked) {
                    $(".member-chk").each(function (index, ele) {
                        var disabled = $(ele).prop("disabled");
                        if (!disabled) {
                            $(ele).prop("checked", true);
                        }
                    });
                } else {
                    $(".member-chk").each(function (index, ele) {
                        var disabled = $(ele).prop("disabled");
                        if (!disabled) {
                            $(ele).prop("checked", false);
                        }
                    });
                }
                form.render('checkbox');
            })
        });
        $("#submitBtn").click(function() {
            $("#myForm").submit();
        });

        $("#resetBtn").click(function() {
            $("#myForm input[type=text]").val("");
            $("#myForm select").find("option:eq(0)").attr("selected", true);
            $(".check-btn-inner").find("a").removeClass("active");
            $(".check-btn-inner").find("a:eq(0)").addClass("active")
            $(".check-btn-inner [name=timeType]").val("");
        });
    });

    function doSubmit(){
        var chkLength = $("[name=id]:checked").length;
        if(chkLength == 0){
            util.layerMsgError("请先选择")
            return false;
        }
        var flag = false;
        var array = new Array();
        $(".member-chk:checked").each(function (index, ele) {
            array.push($(ele).val());
        })

        var ids = array.join(',');
        var loadIndex = layer.load(1, {
            shade: [0.1, '#fff'] //0.1透明度的白色背景
        });
        $.ajax({
            url: '${ctx}/subject/apply/batchSave.do',
            type: "POST",
            dataType: "JSON",
            async: false,
            data: {
                channelId: '${channelId}',
                ids: ids
            },
            success: function (res) {
                top.layer.close(loadIndex);
                if (res.success) {
                    util.layerMsgSuccess("添加成功");
                } else {
                    util.layerMsgError(res.description);
                }
                flag = res.success;
            }
        });

        return flag;
    }


</script>
</body>
</html>